# -*- coding: utf-8 -*-
# @Time:2021/05/20 22:15
# @Author:Cindy

import mitmproxy.http
from mitmproxy import http
from mitmproxy.tools.main import mitmdump


class Events:

    def request(self, flow: mitmproxy.http.HTTPFlow):
        """
            The full HTTP request has been read.
        """
        if 'https://stock.xueqiu.com/v5/stock/batch/quote.json?_t'\
            in flow.request.url and 'x=' in flow.request.url:
            with open('quote.json', encoding='utf-8') as f:
                flow.response = http.HTTPResponse.make(status_code=200,
                                                       content=f.read())

    def response(self, flow: mitmproxy.http.HTTPFlow):
        """
            The full HTTP response has been read.
        """
        pass


addons = [
    Events()
]

if __name__ == '__main__':
    mitmdump(['-p', '8080', '-s', __file__])
